﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WJP.Domain
{
    /// <summary>
    /// 泛型实体列表
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    public class EntityList<T> : EntityList, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable
        where T : Entity
    {
        /// <summary>
        /// 获取或设置指定索引处的元素
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public new T this[int index]
        {
            get => base[index] as T;
            set => this[index] = value;
        }

        /// <summary>
        /// 添加指定的实体到集合中
        /// </summary>
        /// <param name="entity"></param>
        public void Add(T entity)
        {
            base.Add(entity);
        }

        /// <summary>
        /// 判断本集合是否包含指定的实体
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Contains(T entity)
        {
            return base.Contains(entity);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="array"></param>
        /// <param name="arrayIndex"></param>
        public void CopyTo(T[] array, int arrayIndex)
        {
            base.CopyTo(array, arrayIndex);
        }

        /// <summary>
        /// 判断指定的实体在本集合中的索引号
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int IndexOf(T entity)
        {
            return base.IndexOf(entity);
        }

        /// <summary>
        /// 在指定的位置插入实体
        /// </summary>
        /// <param name="index"></param>
        /// <param name="entity"></param>
        public void Insert(int index, T entity)
        {
            base.Insert(index, entity);
        }

        /// <summary>
        /// 在集合中删除指定的实体。返回是否成功删除
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool Remove(T entity)
        {
            return base.Remove(entity);
        }

        /// <summary>
        /// 获取本实体列表的迭代器
        /// </summary>
        /// <returns></returns>
        public IEnumerator<T> GetEnumerator()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 把指定的实体集合都回到本集合中来
        /// </summary>
        /// <param name="entityList"></param>
        public void AddRange(IEnumerable<T> entityList)
        {
            base.AddRange(entityList);
        }
    }
}
